package me.leiusual.sharing.ui.helper

import androidx.lifecycle.Observer
import me.leiusual.sharing.repository.model.DataWrapper

/**
 * author: leiusual
 * create on: 2018/11/14
 * description: 只接受最新数据，主要用于事件处理。
 */
class HandleObserver<T : DataWrapper<*>>(
    private val onUnhandledData: (T) -> Unit
) : Observer<T> {

  override fun onChanged(data: T?) {
    data?.getIfNotHandled()?.let {
      onUnhandledData(data)
    }
  }
}